<template>
  <div class="modifyUserInfo">
 <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="用户名"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="sex"
    type="sex" 
    name="性别"
    label="性别"
    placeholder="性别"
    :rules="[{  message: '请填写性别' }]"
  />
  <van-field
    v-model="telPone"
    name="手机号"
    label="手机号"
    placeholder="手机号"
    :rules="[{ required: true, message: '请填写手机号' }]"
  />
   <van-field
   v-model="email"
    name="email"
    label="email"
    placeholder="email"
    :rules="[{ required: true, message: '请填写email'  }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" >
      修改
    </van-button>
  </div>
</van-form>
  </div>
</template>
<script>

import {getModifyInformation} from "@/api/myLogin.api.js";
import {getPersonalInformation} from "@/api/myLogin.api.js";
import { mapState } from "vuex"
import { Toast } from 'vant';
export default {
  name: "ModifyUserInfo",
  data() {
    return {
      tel: "",
      email: "",
      telPone: "",
      number: "",
      sex: "",
      username:"",
    };
  }, 
  created(){
     this.username=this.userInfo1.userName
     this.telPone=this.userInfo1.phonenumber
     this.email=this.userInfo1.email
     if(this.userInfo1.sex==1){
                this.sex="女"
     }else{
                this.sex="男"

     }

  },
  methods:{
      onSubmit(){
        if(this.sex=="男"){
          this.sex=0
        }else{
          this.sex=1
        }
           getModifyInformation(this.username,this.email,this.telPone,this.sex).then(res=>{
          Toast.success(res.msg);
          getPersonalInformation().then(res=>{
              this.$store.commit('modifyUserInfo',{userInfo1:res.data})
              if(res.data.sex==1){
                this.sex="女"
              }else{
                this.sex="男"
              }
          })
      })
      },
     
  },
   computed: {
        ...mapState(["userInfo1"])
      }
};
</script>
<style lang="stylus" scoped></style>